package com.posjiajia.user.core.bo;

import com.posjiajia.user.core.dao.OrganDao;
import com.posjiajia.user.core.params.OrganQueryParam;
import com.posjiajia.user.core.po.OrganPo;
import com.posjiajia.user.core.utils.BeanTransferUtil;
import com.posjiajia.user.core.vo.OrganVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhenhua.sun on 8/24/16.
 */
@Service
public class OrganBo {

    private static final Logger logger = LoggerFactory.getLogger(OrganBo.class);

    @Autowired
    private OrganDao organDao;

    @Autowired
    private SequenceBo sequenceBo;

    public void insert(OrganVo organVo){
        OrganPo organPo = BeanTransferUtil.transferType(organVo,OrganPo.class);
        organPo.setOrganId(sequenceBo.getNextOrganId());
        organDao.insert(organPo);
    }


    public List<OrganVo> query(OrganQueryParam organQueryParam) {
        OrganPo organPo = BeanTransferUtil.transferType(organQueryParam,OrganPo.class);
        List<OrganPo> poList = organDao.query(organPo);
        List<OrganVo> voList;
        voList = BeanTransferUtil.batchTransferType(poList,OrganVo.class);
        return voList;
    }

    /**
     * 查询
     * @param organId
     * @return
     */
    public OrganPo queryByOrganId(Integer organId) {
        return organDao.queryByOrganId(organId);
    }
}
